#!/usr/bin/env python
# -*- coding: utf-8 -*-
'''
                            _ooOoo_  
                           o8888888o  
                           88" . "88  
                          (|  -_-  |)  
                           O\  =  /O  
                        ____/`---'\____  
                      .   ' \\| |// `.  
                       / \\||| : |||// \  
                     / _||||| -:- |||||- \  
                       | | \\\ - /// | |  
                     | \_| ''\---/'' | |  
                      \ .-\__ `-` ___/-. /  
                   ___`. .' /--.--\ `. . __  
                ."" '< `.___\_<|>_/___.' >'"".  
               | | : `- \`.;`\ _ /`;.`/ - ` : | |  
                 \ \ `-. \_ __\ /__ _/ .-` / /  
         ======`-.____`-.___\_____/___.-`____.-'======  
                            `=---='  
  
         .............................................  
                  佛祖镇楼                  BUG辟易  
          佛曰:  
                  写字楼里写字间，写字间里程序员；  
                  程序人员写程序，又拿程序换酒钱。  
                  酒醒只在网上坐，酒醉还来网下眠；  
                  酒醉酒醒日复日，网上网下年复年。  
                  但愿老死电脑间，不愿鞠躬老板前；  
                  奔驰宝马贵者趣，公交自行程序员。  
                  别人笑我忒疯癫，我笑自己命太贱；  
                  不见满街漂亮妹，哪个归得程序员？ 
'''
# @File  : 4.py
# @Author: huguangzhi
# @Drivce: Thinkpad E470
# @ContactEmail : huguangzhi@ucsdigital.com.com 
# @ContactPhone : 13121961510 
# @Date  : 2021/9/2 - 17:17
# @Desc  :

byte_str = "40142000000001c96d203232"

def bit_ana(bit_str, bit_num):
    res = {}
    if bit_num == 1:
        # byte 1
        if bit_str[:2] == "01":
            res["lift_type"] = "升降梯"
        elif bit_str[:2] == "10":
            res["lift_type"] = "自动扶梯"
        elif bit_str[:2] == "11":
            res["lift_type"] = "自动人行道"

        res["lift_SN"] = int(bit_str[2:],2)

    elif bit_num == 2:
        # byte 2
        if bit_str[:2] == "01":
            res["full"] = "下行"
        elif bit_str[:2] == "10":
            res["full"] = "上行"
        elif bit_str[:2] == "00":
            res["full"] = "无方向（升降梯）"

        res["all_floor"] = int(bit_str[2:], 2)

    elif bit_num == 3:
        # byte 3
        if bit_str[:2] == "00":
            res["up_down"] = "正常"
        elif bit_str[:2] == "10":
            res["up_down"] = "满载"
        elif bit_str[:2] == "01":
            res["up_down"] = "超载"

        res["check"] = "自动" if bit_str[3] == "0" else "检修"
        res["door"] = "关门" if bit_str[4] == "0" else "开门"
        res["tel_err"] = "无故障" if bit_str[5] == "0" else "有故障"
        res["err"] = "无故障" if bit_str[5] == "0" else "有故障"

    elif bit_num == 4:
        res["消防运行"] = "退出" if bit_str[0] == "0" else "进入"
        res["地震管制"] = "退出" if bit_str[1] == "0" else "进入"
        res["火灾管制"] = "退出" if bit_str[2] == "0" else "进入"
        res["紧急电源"] = "退出" if bit_str[3] == "0" else "进入"
        res["锁梯状态"] = "退出" if bit_str[4] == "0" else "进入"

    elif bit_num == 5:
        res["低速待机"] = "退出" if bit_str[0] == "0" else "进入"

    elif bit_num == 6:
        pass
    elif bit_num == 7:
        pass
    elif bit_num == 8:
        pass
    elif bit_num == 9:
        pass
    elif bit_num == 10:
        tmp = int(bit_str, 2)
        tmp = int("{0:x}".format(tmp))
        if tmp > 30:
            res["high"] = tmp%30
        else:
            res["high"] = ""

    elif bit_num == 11:
        tmp = int(bit_str, 2)
        tmp = int("{0:x}".format(tmp))
        if tmp >40:
            res["middel"] = "B"
        elif 40 > tmp > 30:
            res["middel"] = tmp%30
        else:
            res["middel"] = ""

    elif bit_num == 12:
        tmp = int(bit_str, 2)
        tmp = int("{0:x}".format(tmp))
        if tmp > 40:
            res["low"] = "A"
        elif 40 > tmp > 30:
            res["low"] = tmp%30

    return res

def desc_lift(byte_str:str):
    res = {}
    stay_floor = ""
    for num in range(0,len(byte_str),2):
        # 拿到各个段的16进制数
        byte_num = num//2 +1
        state_16 = byte_str[num:num+2]
        state_10 = int(state_16, 16) # 转成10进制的
        state_2 = '{:08b}'.format(state_10) # 转成2进制的
        # print(state_2)
        a = bit_ana(state_2,byte_num)

        res.update(a)
        # print(str(res["高位"]))
    res["stay_floor"] = str(res["high"]) + str(res["middel"])+ str(res["low"])
    return res

def get_all_lift(socket_data):
    res = []
    for item in range(0,len(socket_data[6:-2]),12):
        res.append(item)




